package com.jiangnan.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.jiangnan.databinding.ItemCreditLogBinding
import com.jiangnan.entity.CreditLog

class CreditAdapter : BaseQuickAdapter<CreditLog, CreditAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: ItemCreditLogBinding = ItemCreditLogBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: CreditLog?) {
        // 设置item数据
        holder.binding.apply {
            tvReason.text = item?.reason
            tvChange.text = if (item!!.change>0) "+${item.change}" else item.change.toString()
            tvBeforeAfter.text = "${item!!.creditBefore} → ${item.creditAfter}"
            tvTime.text = item!!.createdAt.toString()
        }
    }

}